<?php
header('Content-type:text/html;charset=utf-8');
header('Content-type: application/json');
header('Access-Control-Allow-Origin:*');
include_once './dbConfig.php';
include_once './public.php';
if ($_GET) {
    if (isset($_GET['getType']) && ($_GET['getType']) == 'proData') {
        $id = $_GET['id'];
        $selectSql = 'select * from lgz_product where id = "' . $id . '"';
        $data = selectEvent($selectSql);
        reponseEvent($data);
    }
}
if($_POST) {
    if (isset($_POST['postType']) && ($_POST['postType']) == 'addShopCar') {
        $id = $_POST['id'];
        $user = $_POST['user'];
        $num = $_POST['num'];
        $selectSql = 'select * from lgz_shop_car where pro_id = "'.$id.'" and  username = "'.$user.'" and status = 1';
        $data = selectEvent($selectSql);
        if($data){
            $nums = $num+$data[0]['num'];
            $updateSql = 'update lgz_shop_car set num = "'.$nums.'" where id = "'.$data[0]['id'].'"';
            if($link->query($updateSql)){
                $msg = ['msg' => '添加成功！', 'status' => 1];
            }else{
                $msg = ['msg' => '添加失败！', 'status' => 0];
            }
            reponseEvent($msg);
        }else{
            $time = time()*1000;
            $insertSql = 'insert into lgz_shop_car (pro_id,num,add_time,username) VALUES ("'.$id.'","'.$num.'","'.$time.'","'.$user.'")';
            if($link->query($insertSql)){
                $msg = ['msg' => '添加成功！', 'status' => 1];
            }else{
                $msg = ['msg' => '添加失败！', 'status' => 0];
            }
            reponseEvent($msg);
        }
    }
}